﻿using System;
using System.Collections.Generic;
using System.Text;

namespace StarcraftBot.Wrapper {
    /// <summary>
    /// Positions are measured in pixels and are the highest resolution.
    /// </summary>
    class Position : BwapiObjectContainer<BWAPI.Position> {

        public Position(BWAPI.Position bwapiPosition) : base(bwapiPosition) {
        }
        
        public Position(int x, int y) : base(new BWAPI.Position(x,y)) {
        }

        //---

        public static List<Position> GetListOfPositions(System.Collections.IEnumerable bwapiCollection) {
            List<Position> result = new List<Position>();
            try {
                foreach (BWAPI.Position p in bwapiCollection) {
                    result.Add(new Position(p));
                }
            } catch { }
            return result;
        }


        //---


        public int X { get { return this.BwapiObject.xConst(); } }
        public int Y { get { return this.BwapiObject.yConst(); } }

        /// <summary>
        /// Returns geometric distance to other map position.
        /// </summary>
        /// <param name="otherPosition"></param>
        /// <returns></returns>
        public double GetDistance(Position otherPosition) {
            return this.BwapiObject.getDistance(otherPosition.BwapiObject);
        }

        public double GetDistanceApprox(Position otherPosition) {
            return this.BwapiObject.getApproxDistance(otherPosition.BwapiObject);
        }

        public double GetLength() {
            return this.BwapiObject.getLength();
        }
    }
}
